﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.ComponentModel;
using Zadani09.db.DAO;
using System.Collections.Generic;

namespace Zadani09.db.ODS
{
    [DataObject(true)]
    public class UmelecDataObject : DataObject
    {
        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Umelec> cti(string razeni)
        {
            List<Umelec> list = DAOTovarna.instance.getUmelecDAO().loadList(0, 0);

            if (list == null) list = new List<Umelec>();

            return list;
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Umelec> cti_s_vyhledavanim(string razeni, string hledano, string atribut)
        {
            List<Umelec> list = cti(razeni);
            List<Umelec> vrat = new List<Umelec>();

            foreach (Umelec jeden in list)
            {
                if (najdi(hledano, jeden, atribut))
                {
                    vrat.Add(jeden);
                }
            }

            return (vrat);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Umelec> ctiJednoho(int id)
        {
            List<Umelec> umelci = new List<Umelec>();

            Umelec u = DAOTovarna.instance.getUmelecDAO().load(id.ToString());

            if (u != null) umelci.Add(u);

            return umelci;
        }

        [DataObjectMethod(DataObjectMethodType.Insert)]
        public void vloz(Umelec data)
        {
            DAOTovarna.instance.getUmelecDAO().create(data);
        }

        [DataObjectMethod(DataObjectMethodType.Delete)]
        public void smaz(Umelec data)
        {
            DAOTovarna.instance.getUmelecDAO().delete(data);
        }

        [DataObjectMethod(DataObjectMethodType.Update)]
        public void aktualizuj(Umelec data)
        {
            DAOTovarna.instance.getUmelecDAO().update(data);
        }
    }
}
